package ds.dsr.log;

import ds.dsr.enums.LogEnum;

import java.text.SimpleDateFormat;

/**
 * @author sunchong
 * @date 2018/4/23
 */
public class Logger {
    static SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
    final static String segment =",    ";
    static Logger logger = new Logger();
    public static void info(String msg){
        System.out.println(logger.buildMsg(msg, LogEnum.LOG_INFO.getLevel()));
    }

    public static void warm(String msg){
        System.out.println(logger.buildMsg(msg, LogEnum.LOG_WARM.getLevel()));
    }

    public static void error(String msg){
        System.out.println(logger.buildMsg(msg, LogEnum.LOG_ERROR.getLevel()));
    }

    private StringBuffer buildMsg(String msg, String level){
        StringBuffer sb = new StringBuffer();
        addSegment(sb, "Level:"+level);
        addSegment(sb, "Time:"+sdf.format(System.currentTimeMillis()));
        addSegment(sb, "Thread:"+Thread.currentThread().getName());
        addSegment(sb, "message:"+msg);
        return sb;
    }

    private void addSegment(StringBuffer sb, String msg){
        sb.append(msg+segment);
    }

}
